1 /***
2 * @version $Revision: 1.3 $
3 */
4 package uba.db.sql.interpreter;
5
6 import java.util.ArrayList;
7 import java.util.List;
8
9 import uba.db.Database;
10 import uba.db.ar.AttributeDef;
11 import uba.db.ar.Tupla;
12 import uba.db.ar.TuplaDef;
13 import uba.db.column.ColumnSpecification;
14 import uba.db.sql.language.CreateTable;
15 import uba.db.table.TableSchema;
16
17 public class CreateTableQueryPlan implements SentenceQueryPlan {
18 CreateTable sentence;
19
20 private boolean hasNotifiedResult;
21
22 private Database database;
23
24 private Tupla tuplaToInform;
25
26 private String tableName;
27
28 private List specifications;
29
30 public CreateTableQueryPlan(CreateTable sqlSentence, Database database) {
31 sentence = sqlSentence;
32 this.database = database;
33 specifications = new ArrayList();
34 hasNotifiedResult = false;
35 }
36
37
38
39
40 public void startExecution() {
41 hasNotifiedResult = false;
42 sentence.accept(new CreateTableVisitor(this));
43 try {
44 database.createTable(new TableSchema(tableName, specifications));
45 tuplaToInform = successTupla();
46 } catch (Exception e) {
47 tuplaToInform = errorTupla();
48 }
49 }
50
51
52
53
54 public boolean hasMoreResults() {
55 return (!hasNotifiedResult);
56 }
57
58 public Tupla successTupla() {
59 TuplaDef def = new TuplaDef();
60 def.addDefinition(new AttributeDef("Resultado del create table"));
61 Tupla tuple = new Tupla(def);
62 tuple.set(1, "Execución exitosa.");
63 return tuple;
64 }
65
66 public Tupla errorTupla() {
67 TuplaDef def = new TuplaDef();
68 def.addDefinition(new AttributeDef("Error"));
69 Tupla errorTuple = new Tupla(def);
70 errorTuple.set(1, "La ejecución no pudo concretarse.");
71 return errorTuple;
72 }
73
74 public Tupla nextTuple() {
75 hasNotifiedResult = true;
76 return tuplaToInform;
77 }
78
79 public String planDetail() {
80 return sentence.toString() + "\t";
81 }
82
83
84
85
86 public TuplaDef tuplaDefinition() {
87 return tuplaToInform.tuplaDefinition();
88 }
89
90 public void setTableName(String name) {
91 tableName = name;
92 }
93
94 public void addColumnSpecification(ColumnSpecification spec) {
95 specifications.add(spec);
96 }
97
98 }